#include "TriangleList.h"
#include "IndexedFace.h"

#include <string>
TriangleList::TriangleList(int nrOfTriangles)
	:m_CurrentIndex(0),m_NrOfTriangles(nrOfTriangles)
{
}

TriangleList::~TriangleList(void)
{
}

int TriangleList::AddIndexedFace(IndexedFace face){
	return AddIndexedFace(face.m_Index1,face.m_Index2,face.m_Index3);
}

int TriangleList::AddIndexedFace(int index1,int index2,int index3)
{
	m_Indices.push_back(index1);
	m_Indices.push_back(index2);
	m_Indices.push_back(index3);
	m_CurrentIndex+=3;
	CheckIndex(index1);
	CheckIndex(index2);
	CheckIndex(index3);
	return GetCurrentNrOfTriangles() -1;
}

void TriangleList::GetIndexedFace(int triangleIndex, int* index1, int* index2, int* index3 ){
	int bi = triangleIndex*3;
	*index1 = m_Indices[bi];
	*index2 = m_Indices[bi+1];
	*index3 = m_Indices[bi+2];
}

void TriangleList::SetIndexedFace(int triangleIndex,int index1,int index2,int index3)
{
	int bi = triangleIndex*3;
	m_Indices[bi]=index1;
	m_Indices[bi+1]=index2;
	m_Indices[bi+2]=index3;
}

void TriangleList::UpdateIndices()
{
	for(int i = 0 ; i< m_NrOfTriangles * 3 ; ++i){
		CheckIndex( m_Indices[i]);
	}
}